package com.hoo.test;

import java.util.List;

import com.hoo.entity.Hobby;
import com.hoo.entity.User;
import com.hoo.utils.FastJsonTools;
import com.hoo.utils.ReadUtil;

public class JsontoHtml {
	
	public static void main(String[] args) {
		StringBuffer sb = new StringBuffer();
		String readJson = ReadUtil.readJson("D:/v16/mars/fastJsonDemo/src/data/simple_Object.json");
		User bean = FastJsonTools.getBean(readJson, User.class);
		sb.append("<table border='1' width='50%'>");
		sb.append("<tr><td>姓名</td><td>"+bean.getName()+"</td></tr>");
		sb.append("<tr><td>年龄</td><td>"+bean.getAge()+"</td></tr>");
		sb.append("<tr><td>性别</td><td>"+bean.getSex()+"</td></tr>");
		sb.append("</table>");
		sb.append("<br>");
		System.out.println(sb.toString());
		readJson = ReadUtil.readJson("D:/v16/mars/fastJsonDemo/src/data/arrayList_test.json");
		List<User> listBean = FastJsonTools.getBeans(readJson, User.class);
		sb.append("<table border='1' width='50%'>");
		for(User u:listBean){
			sb.append("<tr><td>姓名</td><td>"+u.getName()+"</td></tr>");
			sb.append("<tr><td>年龄</td><td>"+u.getAge()+"</td></tr>");
			sb.append("<tr><td>性别</td><td>"+u.getSex()+"</td></tr>");
		}
		sb.append("</table>");
		sb.append("<br>");
		readJson = ReadUtil.readJson("D:/v16/mars/fastJsonDemo/src/data/complex_object.json");
		User bean2 = FastJsonTools.getBean(readJson,User.class);
		sb.append("<table border='1' width='50%'>");
		sb.append("<tr><td>姓名</td><td>"+bean2.getName()+"</td><td></td></tr>");
		sb.append("<tr><td>年龄</td><td>"+bean2.getAge()+"</td><td></td></tr>");
		sb.append("<tr><td>性别</td><td>"+bean2.getSex()+"</td><td></td></tr>");
		sb.append("<tr><td></td><td></td><td>");
		sb.append("<table border='1' width='100%'>");
		for(Hobby ho:bean2.getHobbies()){
			sb.append("<tr><td>爱好</td><td>"+ho.getName()+"</td><td>时长</td><td>"+ho.gethYear()+"</td></tr>");
		}
		sb.append("</table></td></tr>");
		sb.append("</table>");
		sb.append("<br>");
		System.out.println(sb.toString());
	}

}
